package com.everest.tribalapp;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Plik_form2 extends Activity{
	private int flag;
	private int id;
	private String[] choice;
	private String selectvalue;
	private Button form2;
	private Button form2ba;
	private int value;
	private TextView plik_form2_qus1;
	private TextView plik_form2_qus2;
	private TextView plik_form2_qus3;
	private TextView plik_form2_qus4a1;
	private TextView plik_form2_qus4a2;
	private TextView plik_form2_qus4a3;
	private TextView plik_form2_qus4a4;
	private TextView plik_form2_qus4a5;
	private TextView plik_form2_qus4b1;
	private TextView plik_form2_qus4b2;
	private TextView plik_form2_qus4b3;
	private TextView plik_form2_qus4b4;
	private TextView plik_form2_qus4b5;
	private TextView plik_form2_qus4c1;
	private TextView plik_form2_qus4c2;
	private TextView plik_form2_qus4c3;
	private TextView plik_form2_qus4c4;
	private TextView plik_form2_qus4c5;
	private EditText plik_form2_ans4a1;
	private EditText plik_form2_ans4a2;
	private EditText plik_form2_ans4a3;
	private EditText plik_form2_ans4a4;
	private EditText plik_form2_ans4a5;
	private EditText plik_form2_ans4b1;
	private EditText plik_form2_ans4b2;
	private EditText plik_form2_ans4b3;
	private EditText plik_form2_ans4b4;
	private EditText plik_form2_ans4b5;
	private EditText plik_form2_ans4c1;
	private EditText plik_form2_ans4c2;
	private EditText plik_form2_ans4c3;
	private EditText plik_form2_ans4c4;
	private EditText plik_form2_ans4c5;
	private EditText plik_form2_ans1;
	private EditText plik_form2_ans2;
	private EditText plik_form2_ans3;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Plik_form2.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.plik_form2);
		
		form2=(Button)findViewById(R.id.plik_form2_b2);
		form2ba=(Button)findViewById(R.id.plik_form2_b1);
		form2.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent in=new Intent(Plik_form2.this,Plik_form3.class);
				startActivity(in);
				Plik_form2.this.finish();
			}
		});
		form2ba.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent in=new Intent(Plik_form2.this,Plik_form1.class);
				startActivity(in);
				Plik_form2.this.finish();
			}
		});
		decl();
		qus();
		ans();
	}
void decl()
{
	plik_form2_qus1=(TextView)findViewById(R.id.plik_form2_qus1);
	plik_form2_qus2=(TextView)findViewById(R.id.plik_form2_qus2);
	plik_form2_qus3=(TextView)findViewById(R.id.plik_form2_qus3);
	plik_form2_qus4a1=(TextView)findViewById(R.id.plik_form2_qus4a1);
	plik_form2_qus4a2=(TextView)findViewById(R.id.plik_form2_qus4a2);
	plik_form2_qus4a3=(TextView)findViewById(R.id.plik_form2_qus4a3);
	plik_form2_qus4a4=(TextView)findViewById(R.id.plik_form2_qus4a4);
	plik_form2_qus4a5=(TextView)findViewById(R.id.plik_form2_qus4a5);
	plik_form2_qus4b1=(TextView)findViewById(R.id.plik_form2_qus4b1);
	plik_form2_qus4b2=(TextView)findViewById(R.id.plik_form2_qus4b2);
	plik_form2_qus4b3=(TextView)findViewById(R.id.plik_form2_qus4b3);
	plik_form2_qus4b4=(TextView)findViewById(R.id.plik_form2_qus4b4);
	plik_form2_qus4b5=(TextView)findViewById(R.id.plik_form2_qus4b5);
	plik_form2_qus4c1=(TextView)findViewById(R.id.plik_form2_qus4c1);
	plik_form2_qus4c2=(TextView)findViewById(R.id.plik_form2_qus4c2);
	plik_form2_qus4c3=(TextView)findViewById(R.id.plik_form2_qus4c3);
	plik_form2_qus4c4=(TextView)findViewById(R.id.plik_form2_qus4c4);
	plik_form2_qus4c5=(TextView)findViewById(R.id.plik_form2_qus4c5);
	plik_form2_ans1=(EditText)findViewById(R.id.plik_form2_ans1);
	plik_form2_ans2=(EditText)findViewById(R.id.plik_form2_ans2);
	plik_form2_ans3=(EditText)findViewById(R.id.plik_form2_ans3);
	plik_form2_ans4a1=(EditText)findViewById(R.id.plik_form2_ans4a1);
	plik_form2_ans4a2=(EditText)findViewById(R.id.plik_form2_ans4a2);
	plik_form2_ans4a3=(EditText)findViewById(R.id.plik_form2_ans4a3);
	plik_form2_ans4a4=(EditText)findViewById(R.id.plik_form2_ans4a4);
	plik_form2_ans4a5=(EditText)findViewById(R.id.plik_form2_ans4a5);
	plik_form2_ans4b1=(EditText)findViewById(R.id.plik_form2_ans4b1);
	plik_form2_ans4b2=(EditText)findViewById(R.id.plik_form2_ans4b2);
	plik_form2_ans4b3=(EditText)findViewById(R.id.plik_form2_ans4b3);
	plik_form2_ans4b4=(EditText)findViewById(R.id.plik_form2_ans4b4);
	plik_form2_ans4b5=(EditText)findViewById(R.id.plik_form2_ans4b5);
	plik_form2_ans4c1=(EditText)findViewById(R.id.plik_form2_ans4c1);
	plik_form2_ans4c2=(EditText)findViewById(R.id.plik_form2_ans4c2);
	plik_form2_ans4c3=(EditText)findViewById(R.id.plik_form2_ans4c3);
	plik_form2_ans4c4=(EditText)findViewById(R.id.plik_form2_ans4c4);
	plik_form2_ans4c5=(EditText)findViewById(R.id.plik_form2_ans4c5);
}
void qus()
{
	plik_form2_qus1.setOnClickListener(new View.OnClickListener() {
		
		

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			value=R.string.plik_form2_qus1;
			toast_msg();
		}
	});
plik_form2_qus2.setOnClickListener(new View.OnClickListener() {
		
		

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			value=R.string.plik_form2_qus2;
			toast_msg();
		}
	});
plik_form2_qus3.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus3;
		toast_msg();
	}
});
plik_form2_qus4a1.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4a1;
		toast_msg();
	}
});
plik_form2_qus4a2.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4a2;
		toast_msg();
	}
});
plik_form2_qus4a3.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4a3;
		toast_msg();
	}
});
plik_form2_qus4a4.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4a4;
		toast_msg();
	}
});
plik_form2_qus4a5.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4a5;
		toast_msg();
	}
});
plik_form2_qus4b1.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4b1;
		toast_msg();
	}
});
plik_form2_qus4b2.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4b2;
		toast_msg();
	}
});
plik_form2_qus4b3.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4b3;
		toast_msg();
	}
});
plik_form2_qus4b4.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4b4;
		toast_msg();
	}
});
plik_form2_qus4b5.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4b5;
		toast_msg();
	}
});
plik_form2_qus4c1.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4c1;
		toast_msg();
	}
});
plik_form2_qus4c2.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4c2;
		toast_msg();
	}
});
plik_form2_qus4c3.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4c3;
		toast_msg();
	}
});
plik_form2_qus4c4.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4c4;
		toast_msg();
	}
});
plik_form2_qus4c5.setOnClickListener(new View.OnClickListener() {
	
	

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		value=R.string.plik_form2_qus4c5;
		toast_msg();
	}
});
}
void ans()
{
plik_form2_ans4a1.setOnTouchListener(new OnTouchListener() {
	
	

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4a1.setFocusable(false);
		id=plik_form2_ans4a1.getId();
		choice=new String[]{"Laki-laki","Perempuan"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4a2.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4a2.setFocusable(false);
		id=plik_form2_ans4a2.getId();
		choice=new String[]{"SD","SMP","SLTA","diploma keatas"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4a3.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4a3.setFocusable(false);
		id=plik_form2_ans4a3.getId();
		choice=new String[]{"Ya","Tidak"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4a4.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4a4.setFocusable(false);
		id=plik_form2_ans4a4.getId();
		choice=new String[]{"Ya","Tidak"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4a5.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4a5.setFocusable(false);
		id=plik_form2_ans4a5.getId();
		choice=new String[]{"Ya","Tidak"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4b1.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4b1.setFocusable(false);
		id=plik_form2_ans4b1.getId();
		choice=new String[]{"Laki-laki","Perempuan"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4b2.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4b2.setFocusable(false);
		id=plik_form2_ans4b2.getId();
		choice=new String[]{"SD","SMP","SLTA","diploma keatas"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4b3.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4b3.setFocusable(false);
		id=plik_form2_ans4b3.getId();
		choice=new String[]{"Ya","Tidak"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4b4.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4b4.setFocusable(false);
		id=plik_form2_ans4b4.getId();
		choice=new String[]{"Ya","Tidak"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4b5.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4b5.setFocusable(false);
		id=plik_form2_ans4b5.getId();
		choice=new String[]{"Ya","Tidak"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4c1.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4c1.setFocusable(false);
		id=plik_form2_ans4c1.getId();
		choice=new String[]{"Laki-laki","Perempuan"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4c2.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4c2.setFocusable(false);
		id=plik_form2_ans4c2.getId();
		choice=new String[]{"SD","SMP","SLTA","diploma keatas"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4c3.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4c3.setFocusable(false);
		id=plik_form2_ans4c3.getId();
		choice=new String[]{"Ya","Tidak"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4c4.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4c4.setFocusable(false);
		id=plik_form2_ans4c4.getId();
		choice=new String[]{"Ya","Tidak"};
		singlechoice();
		return false;
	}
});
plik_form2_ans4c5.setOnTouchListener(new OnTouchListener() {
	
	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		flag++;
		plik_form2_ans4c5.setFocusable(false);
		id=plik_form2_ans4c5.getId();
		choice=new String[]{"Ya","Tidak"};
		singlechoice();
		return false;
	}
});
}

public void toast_msg()
{
	LayoutInflater inflater = getLayoutInflater();

	View layout = inflater.inflate(R.layout.custom_toast,
			(ViewGroup) findViewById(R.id.custom_toast_layout_id));
	TextView text = (TextView) layout.findViewById(R.id.text);
	text.setText(value);
	Toast toast = new Toast(getApplicationContext());
	toast.setGravity(Gravity.BOTTOM, 0, 0);
	toast.setDuration(Toast.LENGTH_LONG);
	toast.setView(layout);
	toast.show();
}
void singlechoice()
{
	if(flag==1)
	{
		Builder builder=new AlertDialog.Builder(this);
		builder.setTitle("Number of items");
		builder.setSingleChoiceItems(choice, -1, new DialogInterface.OnClickListener() {
			
			

			@Override
			public void onClick(DialogInterface dialog, int count) {
				// TODO Auto-generated method stub
				selectvalue=""+(count+1);
				update();
				flag=0;
				dialog.dismiss();
			}
		});
		builder.setNegativeButton("cancel",new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				flag=0;
	             dialog.dismiss();  
			}
		});
		AlertDialog alert=builder.create();
		alert.show();
	}
}
protected void update()
{
	if(id==plik_form2_ans4a1.getId())
	{
		plik_form2_ans4a1.setText(selectvalue);
	}
	if(id==plik_form2_ans4a2.getId())
	{
		plik_form2_ans4a2.setText(selectvalue);
	}
	if(id==plik_form2_ans4a3.getId())
	{
		plik_form2_ans4a3.setText(selectvalue);
	}
	if(id==plik_form2_ans4a4.getId())
	{
		plik_form2_ans4a4.setText(selectvalue);
	}
	if(id==plik_form2_ans4a5.getId())
	{
		plik_form2_ans4a5.setText(selectvalue);
	}
	if(id==plik_form2_ans4b1.getId())
	{
		plik_form2_ans4b1.setText(selectvalue);
	}
	if(id==plik_form2_ans4b2.getId())
	{
		plik_form2_ans4b2.setText(selectvalue);
	}
	if(id==plik_form2_ans4b3.getId())
	{
		plik_form2_ans4b3.setText(selectvalue);
	}
	if(id==plik_form2_ans4b4.getId())
	{
		plik_form2_ans4b4.setText(selectvalue);
	}
	if(id==plik_form2_ans4b5.getId())
	{
		plik_form2_ans4b5.setText(selectvalue);
	}
	if(id==plik_form2_ans4c1.getId())
	{
		plik_form2_ans4c1.setText(selectvalue);
	}
	if(id==plik_form2_ans4c2.getId())
	{
		plik_form2_ans4c2.setText(selectvalue);
	}
	if(id==plik_form2_ans4c3.getId())
	{
		plik_form2_ans4c3.setText(selectvalue);
	}
	if(id==plik_form2_ans4c4.getId())
	{
		plik_form2_ans4c4.setText(selectvalue);
	}
	if(id==plik_form2_ans4c5.getId())
	{
		plik_form2_ans4c5.setText(selectvalue);
	}
}

@Override
protected void onPause() {
	// TODO Auto-generated method stub
	super.onPause();
	SharedPreferences preferences=getSharedPreferences("plik_f2_details",MODE_PRIVATE);
	SharedPreferences.Editor editor=preferences.edit();
	editor.putString("2_1", plik_form2_ans1.getText().toString().trim());
	editor.putString("2_2", plik_form2_ans2.getText().toString().trim());
	editor.putString("2_3", plik_form2_ans3.getText().toString().trim());
	editor.putString("2_4a1", plik_form2_ans4a1.getText().toString().trim());
	editor.putString("2_4a2", plik_form2_ans4a2.getText().toString().trim());
	editor.putString("2_4a3", plik_form2_ans4a3.getText().toString().trim());
	editor.putString("2_4a4", plik_form2_ans4a4.getText().toString().trim());
	editor.putString("2_4a5", plik_form2_ans4a5.getText().toString().trim());
	editor.putString("2_4b1", plik_form2_ans4b1.getText().toString().trim());
	editor.putString("2_4b2", plik_form2_ans4b2.getText().toString().trim());
	editor.putString("2_4b3", plik_form2_ans4b3.getText().toString().trim());
	editor.putString("2_4b4", plik_form2_ans4b4.getText().toString().trim());
	editor.putString("2_4b5", plik_form2_ans4b5.getText().toString().trim());
	editor.putString("2_4c1", plik_form2_ans4c1.getText().toString().trim());
	editor.putString("2_4c2", plik_form2_ans4c2.getText().toString().trim());
	editor.putString("2_4c3", plik_form2_ans4c3.getText().toString().trim());
	editor.putString("2_4c4", plik_form2_ans4c4.getText().toString().trim());
	editor.putString("2_4c5", plik_form2_ans4c5.getText().toString().trim());
	editor.commit();
	
}

@Override
protected void onResume() {
	// TODO Auto-generated method stub
	super.onResume();
	SharedPreferences preferences=getSharedPreferences("plik_f2_details",MODE_PRIVATE);
	plik_form2_ans1.setText(preferences.getString("2_1", ""));
	plik_form2_ans2.setText(preferences.getString("2_2", ""));
	plik_form2_ans3.setText(preferences.getString("2_3", ""));
	plik_form2_ans4a1.setText(preferences.getString("2_4a1", ""));
	plik_form2_ans4a2.setText(preferences.getString("2_4a2", ""));
	plik_form2_ans4a3.setText(preferences.getString("2_4a3", ""));
	plik_form2_ans4a4.setText(preferences.getString("2_4a4", ""));
	plik_form2_ans4a5.setText(preferences.getString("2_4a5", ""));
	plik_form2_ans4b1.setText(preferences.getString("2_4b1", ""));
	plik_form2_ans4b2.setText(preferences.getString("2_4b2", ""));
	plik_form2_ans4b3.setText(preferences.getString("2_4b3", ""));
	plik_form2_ans4b4.setText(preferences.getString("2_4b4", ""));
	plik_form2_ans4b5.setText(preferences.getString("2_4b5", ""));
	plik_form2_ans4c1.setText(preferences.getString("2_4c1", ""));
	plik_form2_ans4c2.setText(preferences.getString("2_4c2", ""));
	plik_form2_ans4c3.setText(preferences.getString("2_4c3", ""));
	plik_form2_ans4c4.setText(preferences.getString("2_4c4", ""));
	plik_form2_ans4c5.setText(preferences.getString("2_4c5", ""));
}
}
